<template>
  <v-card :title="title" @submit="submit" @reset="reset">
    <v-form
      slot="form"
      :form-title="formTitle"
      :form-data="formData"

    />
  </v-card>
</template>

<script>

export default {
  data() {
    return {
      mp_id: '',
      title: '创建',
      permissionList: [],
      formData: {
        PermissionsIdList: [],
        menuIdList: []
      }

    }
  },
  computed: {
    formTitle() {
      return ([
        {
          cn: 'id',
          en: 'id',
          disabled: true
        },
        {
          en: 'slug',
          cn: '标识'
        },
        {
          en: 'name',
          cn: '名称'
        },
        {
          en: 'PermissionsIdList',
          cn: '权限',
          type: 'checkbox',
          list: this.permissionList
        },
        {
          cn: '创建时间',
          en: 'created_at',
          disabled: true
        },
        {
          cn: '更新时间',
          en: 'updated_at',
          disabled: true
        }
      ])
    }
  },
  activated() {
    this.getPermissionList()
    this.$emit('childTitle', this.$route.meta.title1)
  },
  methods: {
    // 获取所有权限列表
    getPermissionList() {
      this.$get('action/Permissions/dataGrid').then(res => {
        this.permissionList = res.data.map(item => {
          return {
            label: item.name,
            value: item.id
          }
        }) || []
      })
    },
    submit() {
      this.formData.PermissionsIdList = this.formData.PermissionsIdList.toString()
      const data = this.formData
      this.$post('action/PositionCtrl/save', data)
        .then(res => {
          this.$message({
            message: res.msg,
            type: 'success'
          })
        })
    },
    reset() {
      this.formData = {
        PermissionsIdList: [],
        menuIdList: []
      }
    }

  }
}
</script>

<style scoped>

</style>
